# 使用threading模块创建线程
import threading, time, os


def fun():
    for i in range(2):
        time.sleep(1)
        print("线程的名字：", threading.current_thread().getName())


if __name__ == "__main__":
    print("主进程开始， pid:", os.getpid())
    threads = [threading.Thread(target=fun) for i in range(4)]  # 创建4个线程

    for t in threads:
        t.start()

    print("主进程结束， pid:", os.getpid())
    time.sleep(100)  # 防止主进程过早退出
